package core.voyageur;

import java.util.ArrayList;
import java.util.Hashtable;

import core.ClasseVol;
import core.vols.Prix;
import core.vols.VolInstance;

public class Billet implements Comparable {
	
	private Client client;
	private ArrayList<VolInstance> vols;
	private Hashtable<VolInstance, ClasseVol> classes;
	private Prix prix;
	

	/**
	 * @param passager
	 * @param billets
	 */
	public Billet(Client client, ArrayList<VolInstance> billets, Hashtable<VolInstance, ClasseVol> classes) {
		super();
		this.client = client;
		this.vols = billets;
		this.prix = new Prix();
		this.classes = classes;
		prix.calculate(billets, client, classes);
	}

	/**
	 * @return the passager
	 */
	public Client getClient() {
		return client;
	}

	/**
	 * @return the billets
	 */
	public ArrayList<VolInstance> getVols() {
		return vols;
	}
	
	public void addVol (VolInstance v) {
		vols.add(v);
	}
	
	public void removeVol (VolInstance v) {
		vols.remove(v);
	}
	
	public void removeVol (int ind) {
		vols.remove(ind);
	}
	
	public void remplacerVol (VolInstance vOriginal, VolInstance vNouveau) {
		vols.add(vols.indexOf(vOriginal), vNouveau);
		vols.remove(vOriginal);
		vNouveau.addCandidat(client);
	}
	
	public int nbVol () {
		return vols.size();
	}
	
	public VolInstance getVol (int ind) {
		return vols.get(ind);
	}

	@Override
	public int compareTo(Object o) {
		if(o instanceof Billet) {
			if(this.vols.get(0).getDate().compareTo(((Billet) o).vols.get(0).getDate()) < 0) return -1;
			else if (this.vols.get(0).getDate().compareTo(((Billet) o).vols.get(0).getDate()) > 0) return 1;
			else return (this.vols.get(0).getHeureDepart().compareTo(((Billet)o).vols.get(0).getHeureDepart()));
		}
			return 0;
	}
	
	public String toString() {
		String s = "";
		for(VolInstance v : vols) s += v.toString() +"["+ classes.get(v).toString() +"]" + " -> ";
		return s.substring(0, s.lastIndexOf("-")-1);
	}

}
